import sys
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QProgressBar, QPushButton, QLineEdit
from MainWindow import Ui_MainWindow
from douyin_download import DouyinDownload


class DownloadThread(QThread):
    finished = pyqtSignal(str)

    def __init__(self, target):
        super().__init__()
        self.target = target

    def run(self):
        self.target()
        self.finished.emit("下载完成")


def download(share_url, douyin_download, progressbar, download_text, msgBox):
    if len(share_url) == 0:
        return
    douyin_download.share_link_desc = share_url
    print('download...')
    thread = DownloadThread(target=douyin_download.download_share)
    # thread.finished.connect(lambda result: completed(result, douyin_download, progressbar, download_text, msgBox))
    thread.start()
    progressbar.setVisible(True)
    download_text.setVisible(True)


def main():
    share_url = '5.66 复制打开抖音，看看【小甘电影的作品】献给家长和小大人的一部佳片# 一剪到底  https://v.douyin.com/ikMsJaQr/ J@i.Pk jca:/ 02/21 '  # 在这里设置 share_url
    #     创建一个douyin_download类型的对象
    douyin_download = DouyinDownload()
    douyin_download.share_link_desc = share_url
    douyin_download.download_share()


if __name__ == '__main__':
    main()
